﻿
Imports System.Runtime.CompilerServices

Public Module _strrplc
    <Extension()> Public Function strrplc(ByRef str As String, ByVal index As Int64, ByVal s As String) As String
        If Not String.IsNullOrEmpty(str) Then
            Select Case strlen(str)
                Case Is > index
                    str = strleft(str, index) + s + strmid(str, index + strlen(s))
                Case index
                    str += s
            End Select
        End If
        Return str
    End Function

    <Extension()> Public Function strrplc(ByRef s As String, ByVal [from] As String, ByVal [to] As String) As String
        If Not String.IsNullOrEmpty(s) AndAlso Not String.IsNullOrEmpty([from]) Then
            s = s.Replace([from], [to])
        End If
        Return s
    End Function

    <Extension()> Public Function strrplc(ByRef s As String, ByVal [from] As Char, ByVal [to] As Char) As String
        If Not String.IsNullOrEmpty(s) Then
            s = s.Replace([from], [to])
        End If
        Return s
    End Function
End Module
